<template>
  <div>

    <van-cell-group>
      <van-cell title="订单号" :value="val_.num" />
      <van-cell title="创建时间" :value="val_.addtime" />
      <van-cell title="状态" :value="val_.state==1?'已发货':'未发货'" />
      <van-cell title="果品" :value="val_.guopin" />
      <van-cell title="数量" :value="val_.sum" />
      <van-cell title="规格" :value="val_.guige" />
      <van-cell title="快递地址" :value="val_.site" />
    </van-cell-group>


    <div class="btnm">
      <van-button  type="primary" @click="goEdit">修改</van-button>
      <van-button  type="warning" @click="goDel">删除</van-button>
      <van-button  type="default" @click="goBack" >返回</van-button>
    </div>

    <van-dialog id="van-dialog" />

  </div>
</template>

<script>
  import Dialog from '../../../static/vant/dialog/dialog';
  import * as dayjs from 'dayjs'
  import 'dayjs/locale/zh-cn' // import locale
  import {orderEdit,orderiInfo,categoryList} from '../../api/basisMG'


export default {
  data () {
    return {
      val_:{
        guopin:"",
        guige:"",
        site:"",
        sum:"",
        num:"",
        addtime:""
      },
      username:"",
      show_guopin:false,
      show_guige:false

    }
  },
  mounted() {
    let t = this
    orderiInfo({"_id":this.$root.$mp.query.id}).then(res => {
      if(res.data){
        this.val_ = res.data
        function id2time(id) {
          return dayjs(parseInt(id.toString().substring(0, 8), 16) * 1000).format('YYYY-MM-DD HH:mm:ss');
        }
        this.val_.addtime = id2time(res.data._id)
      }
      categoryList({"id":this.val_.guopin}).then(res => {
          if(res.data){
            this.val_.guopin = res.data[0].text
            this.val_.guige =res.data[0].children.filter((obj,index)=>{
              if(obj.id ==this.val_.guige){
                return obj
              }
            })[0].text
            this.val_.guige = res.data[0].children[this.val_.guige].text
          }
        }
      )
    })
  },
  methods: {
    goEdit(){
      let _id = this.$root.$mp.query.id
      wx.redirectTo({
        url: "/pages/order_add/main?id="+_id
      })
    },
    goBack(){
      wx.navigateBack({
        delta: 1
      })
    },
    goDel(){
      var timestamp = Date.parse(new Date());
      orderEdit({"_id":this.val_._id,"deltime":timestamp/1000}).then(res => {
        Dialog.alert({
          message: '已放入回收站'
        }).then(() => {
          wx.navigateBack({
            delta: 1
          })
        });
      })
    }
  },


}
</script>

<style >

  page {
    background-color: #fff;
  }
  .btnm{
    text-align: center;
    padding-top: 20rpx;
  }

  .table_parent {
    display:flex;
    justify-content:center;
    align-items:center;
    background: white;
    font-size:30rpx;
    text-align:center;
    box-sizing:border-box;
    color:#595a5e;
    padding-top: 20rpx;
    padding-bottom: 20rpx;
  }
  .table {
    border: 1px solid #dadada;
    border-right: 0;
    border-bottom: 0;
    width: 98%;
  }

  .tr {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }

  .th, .td {
    padding: 10px;
    border-bottom: 1px solid #dadada;
    border-right: 1px solid #dadada;
    text-align: center;
    width: 100%;
  }

  .th {
    font-weight: 400;
    background-color: #dadada;
  }
  ._van-button{margin: 1%;padding: 0}
  ._van-button button {padding: 0}
  .van-button--normal {padding: 0rpx !important; width: 30%}

</style>
